package vip.liux.backend.application.service.pay;

import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;
import vip.liux.backend.application.service.pay.dto.app.PayAppCreateDto;
import vip.liux.backend.application.service.pay.dto.app.PayAppDto;
import vip.liux.backend.application.service.pay.dto.app.PayAppPageItemDto;
import vip.liux.backend.application.service.pay.dto.app.PayAppUpdateDto;
import vip.liux.backend.application.service.pay.dto.channel.PayChannelCreateDto;
import vip.liux.backend.application.service.pay.dto.channel.PayChannelDto;
import vip.liux.backend.application.service.pay.dto.channel.PayChannelUpdateDto;
import vip.liux.backend.application.service.pay.dto.notify.PayNotifyTaskDetailDto;
import vip.liux.backend.application.service.pay.dto.notify.PayNotifyTaskDto;
import vip.liux.backend.application.service.pay.dto.order.*;
import vip.liux.backend.application.service.pay.dto.refund.PayRefundDetailsDto;
import vip.liux.backend.application.service.pay.dto.refund.PayRefundPageItemDto;
import vip.liux.backend.application.service.pay.dto.transfer.PayTransferCreateDto;
import vip.liux.backend.application.service.pay.dto.transfer.PayTransferDto;
import vip.liux.backend.application.service.pay.dto.wallet.PayWalletDto;
import vip.liux.backend.application.service.pay.dto.wallet.PayWalletRechargeDto;
import vip.liux.backend.application.service.pay.dto.wallet.PayWalletTransactionDto;
import vip.liux.backend.application.service.pay.dto.wallet.WalletTransactionCreateDto;
import vip.liux.contracts.infrastructure.automap.IgnoreAudited;
import vip.liux.contracts.infrastructure.automap.IgnoreCreationAudited;
import vip.liux.contracts.infrastructure.automap.MapMapper;
import vip.liux.contracts.infrastructure.automap.MapStructConfig;
import vip.liux.contracts.infrastructure.pay.dto.order.ClientPayOrderDto;
import vip.liux.contracts.infrastructure.pay.dto.order.PayOrderUnifiedDto;
import vip.liux.contracts.infrastructure.pay.dto.transfer.PayTransferUnifiedDto;
import vip.liux.contracts.models.pay.*;

import java.util.List;

@Mapper(config = MapStructConfig.class, uses = {MapMapper.class})
public interface AutoMapperProfile {

    AutoMapperProfile INSTANCE = Mappers.getMapper(AutoMapperProfile.class);

    @Mapping(target = "channelCodes", ignore = true)
    PayAppPageItemDto pageConvert(PayApp bean);

    @IgnoreAudited
    PayApp convert(PayAppCreateDto bean);

    @IgnoreAudited
    void convert(PayAppUpdateDto bean, @MappingTarget PayApp target);

    PayAppDto convert(PayApp payApp);

    List<PayAppDto> convert(List<PayApp> all);

    @IgnoreAudited
    @Mapping(target = "config", ignore = true)
    PayChannel convert(PayChannelCreateDto bean);

    @IgnoreAudited
    @Mapping(target = "code", ignore = true)
    @Mapping(target = "config", ignore = true)
    void convert(PayChannelUpdateDto bean, @MappingTarget PayChannel target);

    @Mapping(target = "configObject", ignore = true)
    PayChannelDto convert(PayChannel bean);

    List<PayChannelDto> convertChannel(List<PayChannel> bean);

    @BeanMapping(ignoreByDefault = true)
    @IgnoreCreationAudited
    PayOrder convert(PayOrderCreateDto bean);

    @Mapping(target = "appName", ignore = true)
    PayOrderDto convert(PayOrder payOrder);

    @Mapping(target = "appName", ignore = true)
    PayOrderDetailsDto convertDetail(PayOrder payOrder);

    List<PayOrderDto> convertList(List<PayOrder> list);

    @BeanMapping(ignoreByDefault = true)
    PayOrderUnifiedDto convert2(PayOrderSubmitInputDto input, String userIp);

    @Mapping(source = "order.status", target = "status")
    PayOrderSubmitDto convert(PayOrder order, ClientPayOrderDto unifiedOrderResp);

    @Mapping(target = "order", ignore = true)
    @Mapping(target = "appName", ignore = true)
    PayRefundDetailsDto convert(PayRefund payRefund);

    @Mapping(target = "appName", ignore = true)
    PayRefundPageItemDto convertPage(PayRefund payRefund);

    PayWalletDto convert(PayWallet wallet);

    PayWalletTransactionDto convert(PayWalletTransaction wallet);

    @Mapping(target = "seqNo", ignore = true)
    @IgnoreCreationAudited
    PayWalletTransaction convert(WalletTransactionCreateDto wallet);

    @Mapping(target = "appName", ignore = true)
    PayNotifyTaskDto convert(PayNotifyTask payNotifyTask);

    PayNotifyTaskDetailDto.Log convert(PayNotifyLog log);

    @Mapping(target = "appName", ignore = true)
    PayNotifyTaskDetailDto convert(PayNotifyTask payNotifyTask, List<PayNotifyTaskDetailDto.Log> logs);

    @Mapping(target = "payOrderChannelOrderNo", ignore = true)
    @Mapping(target = "payChannelName", ignore = true)
    PayWalletRechargeDto convert(PayWalletRecharge recharge);

    @BeanMapping(ignoreByDefault = true)
    @IgnoreCreationAudited
    PayTransfer convert(PayTransferCreateDto input);

    @Mapping(target = "outTransferNo", ignore = true)
    @Mapping(target = "notifyUrl", ignore = true)
    PayTransferUnifiedDto convertToClient(PayTransferCreateDto input);

    @Mapping(target = "appName", ignore = true)
    PayTransferDto convert(PayTransfer payTransfer);
}
